<template>
  <div ref="bar" class="bar">bar</div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "BarCharts",
  mounted() {
    let myCharts = echarts.init(this.$refs.bar);
    let option = {
      title: {
        // text: "123",
      },
      tooltip: {
           confine: true,
        position: function (point, params, dom, rect, size) {
          // 固定在顶部
          return [point[0], "10%"];
        },
      },
      series: {
        type: "bar",
        data:  [34, 27, 53, 22, 65, 49, 24],
                color: {
          type: "linear",
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: "black", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "#eee", // 100% 处的颜色
            },
          ],
          global: false, // 缺省为 false
        },
      },
      xAxis: {
        type: "category",
        show: false,
      },
      yAxis: {
        show: false,
      },
      label: {
        show: true,
      },
      grid:{
          left: 0,
        right: 0,
        top: 0,
        bottom: 0,
      }
    };
    myCharts.setOption(option);

    window.onresize = function(){
      myCharts.resize()
    }
  },
};
</script>

<style lang="scss" scoped>
.bar {
  width: 100%;
  height: 100%;
  // border:1px solid red;
}
</style>